<?php
/**
 * Created by PhpStorm.
 * User: cy
 * Date: 2017/5/30
 * Time: 2:04
 */
header("Access-control-allow-origin:*");//允许跨域



if(!empty($_POST)&&$_POST["username"]!=""&&$_POST["userpwd"]!=""&&$_POST["useremail"]!=""){



//1.与数据库创建连接
    $dbserver="127.0.0.1";
    $dbuser="root";
    $dbpwd="";
    $database="tiangou";

//2.创建连接对象
    $conn=new mysqli($dbserver,$dbuser,$dbpwd,$database);

// 3. 设置连接字符集
    mysqli_query($conn, "set names utf8");

//4.判断一下，是否链接成功
//print_r($conn->connect_error);

//6.编写sql语句
    $sql="INSERT INTO userinfo(uname,upwd,uemail)
VALUES('".$_POST["username"]."','".$_POST["userpwd"]."','".$_POST["useremail"]."')";

//7.执行sql语句并返回结果
    $result=$conn->query($sql);
//print_r($result);
$arr=array();
    array_push($arr,"{status:".$result."}");
    print_r(json_encode($arr));

//5.关闭连接
    $conn->close();

}else {
    array_push($arr,"{status:0}");
    print_r(json_encode($arr));
}


